<script setup>
import {ref, reactive, watch, computed, nextTick, getCurrentInstance} from 'vue'
import SelectPopup from "@/components/selectPopup.vue";
import SelectStore from "@/components/selectStore.vue";
import {uploadUrl, getDeptByParent, getCheckType, getStoreList, getCheckInfoList, createStoreCheckList, modifyStoreCheckList, getrecordbyid, getrecordbyidhare, updateUserSign, delphoto} from "@/api";
import Uploader from "@/components/uploader.vue";
import {host, baseUrl} from "@/utils/config";
import {onLoad} from "@dcloudio/uni-app";
import Signature from "@/components/signature.vue";

const userInfo = uni.getStorageSync('userInfo')
const dict = reactive({})
const formData = ref(null)
const pageData = reactive({
  activeCollapse: 1,
  formData: {
    parentName: '',
    parentId: null,
    csnumber: 1,
    yyzt: 1,
    cengshu: 0,
    mianji: 0,
    yanganshu: 0,
    recorddtls: [
    ]
  },
  checkInfoList: []
})
const formRule = {
  deptName: [
    {
      required: true,
      message: '请选择部门'
    }
  ],
  xqid: [
    {
      required: true,
      message: '请选择辖区'
    }
  ],
  csname: [
    {
      required: true,
      message: '请选择场所',
    }
  ],
  type: [
    {
      required: true,
      message: '请选择场所类别'
    }
  ],
  checktypeid: [
    {
      required: true,
      message: '请选择检查类型'
    }
  ],
  okSign1: [
    {
      required: true,
      message: '请签字'
    }
  ],
  okSign2: [
    {
      required: true,
      message: '请签字'
    }
  ],
  okSign3: [
    {
      required: true,
      message: '请签字'
    }
  ],
  todoSign1: [
    {
      required: true,
      message: '请签字'
    }
  ],
  todoSign2: [
    {
      required: true,
      message: '请签字'
    }
  ],
  todoSign3: [
    {
      required: true,
      message: '请签字'
    }
  ],
  nookSign1: [
    {
      required: true,
      message: '请签字'
    }
  ],
  nookSign2: [
    {
      required: true,
      message: '请签字'
    }
  ],
  nookSign3: [
    {
      required: true,
      message: '请签字'
    }
  ]
}
const placeholder = reactive({
  csnamePh: '请先选择所属管辖',
  checkinfoid: '请先选择检查类型'
})
const remoteParams = reactive({
  xq: {
    api: getDeptByParent,
    params: {
      parentid: userInfo.dept.deptId,
      deptType: '0'
    },
    field: {
      text: 'deptName',
      value: 'deptId'
    }
  },
  checkType: {
    api: getCheckType,
    params: {
      deptId: userInfo.dept.deptId
    },
    field: {
      text: 'typename',
      value: 'id'
    }
  },
  checkInfo: {
    api: getCheckInfoList,
    params: {
      typeid: ''
    },
    field: {
      text: 'content',
      value: 'id'
    }
  },
  store: {
    api: getStoreList,
    params: {
      xqid: null,
      name: ''
    }
  }
})

watch(
    () => pageData.formData.xqid,
    (nv, ov) => {
      console.log(nv, ov)
      remoteParams.store.params.xqid = nv
      nv ? placeholder.csnamePh = '请选择场所' : placeholder.csnamePh = '请先选择所属管辖'
    },
    {
      deep: true
    }
)
watch(
    () => pageData.formData.checktypeid,
    (nv, ov) => {
      console.log(nv, ov)
      console.log('pageData.formData', pageData.formData)
      if (pageData.formData.id || nv === ov) return
      remoteParams.checkInfo.params.typeid = nv
      nv ? placeholder.checkinfoid = '请选择检查内容' : placeholder.checkinfoid = '请先选择检查类型'
      getCheckInfoList(remoteParams.checkInfo.params).then(res => {
        pageData.checkInfoList = res.data.filter(item => item.delFlag === 0).map(item => {
          return {
            value: item.id,
            text: item.content
          }
        })
        pageData.formData.recorddtls = res.data.filter(item => item.delFlag === 0).map(item => {
          return {
            checkinfoid: item.id,
            checkinfo: item.content,
            score: item.score,
            isOk: 1,
            // status: 1,
            checkPhotos: [],
            rectifyPhotos: [],
            placeholder: item.content,
            content: item.zgjy,
            egPic: item.egPic,
          }
        })
      })
    },
    {
      deep: true
    }
)
watch(
    () => pageData.formData.csname,
    (nv, ov) => {
      console.log(nv, ov)
      remoteParams.store.params.name = nv
    },
    {
      deep: true
    }
)
watch(
    () => pageData.formData.recorddtls,
    (nv, ov) => {
      console.log('修改了',nv, ov)
      if (isSubmit.value) return
      if (nv.some(item => item.status === 0)) {
        getFormStatus.value = 2
        pageData.formData.status = 2
        return
      }
      if (nv.some(item => (!item.recordId && item.isOk === 0) || (item.isOk === 0 && pageData.formData.status === 1))) {
        getFormStatus.value = 0
        pageData.formData.status = 0
        return
      }
      getFormStatus.value = 1
      pageData.formData.status = 1
      console.log('status', 1, pageData.formData.status, pageData.formData)
    },
    {
      deep: true
    }
)

const getFormStatus = ref(1)

const isSubmit = ref(false)

const loadingBtn = ref(false)
const visibleScore = ref(false)
const scoreTotalText = ref('')
const clickOk = () => {
  console.log('确定提交呀呀呀晕')
  submit(true)
}
const submit = (submitBool) => {
  console.log('pageData.formData', pageData.formData)
  formData.value.validate().then(({ valid, errors }) => {
    if (valid) {
      // 判断危险总分值是否大于5
      const scoreTotal = pageData.formData.recorddtls.reduce((sum, item) => sum + (item.isOk == 0 ? item.score : 0 || 0), 0);
      const result = scoreTotal > 5;
      if (!pageData.formData.id) {
        pageData.formData.scoreTotal = scoreTotal
      }
      scoreTotalText.value = '该场所危险总分值为'+scoreTotal+'，确定提交？'
      if(result && !pageData.formData.id && !submitBool){
        visibleScore.value = true
        return
      }

      isSubmit.value = true
      pageData.formData.imgList = [
        ...pageData.formData.signboard || [],
        ...pageData.formData.license || [],
      ]
      for (let i = 0; i < pageData.formData.recorddtls.length; i++) {
        pageData.formData.recorddtls[i].photoList = []
        pageData.formData.recorddtls[i].photoList = [
          ...pageData.formData.recorddtls[i].checkPhotos,
          ...pageData.formData.recorddtls[i].rectifyPhotos
        ]
      }
      console.log('提交pagedata', pageData.formData)
      // return
      loadingBtn.value = true
      let api
      let msg = ''
      if (pageData.formData.id) {
        api = modifyStoreCheckList
        msg = '更新成功！'
      } else {
        api = createStoreCheckList
        msg = '新增成功！'
      }
      api(pageData.formData).then(res => {
        console.log('create', res)
        if((!userInfo.signUrl && pageData.formData.okSign1) || (userInfo.signUrl && userInfo.signUrl !== pageData.formData.okSign1)) {
          const params = {
            userId: userInfo.userId,
            signUrl: pageData.formData.okSign1
          }
          updateUserSign(params)
        }
        uni.showToast({
          title: msg
        })
        isSubmit.value = false
        uni.navigateBack()
      }).catch(err => {
        loadingBtn.value = false
      })
    }
    else {
      console.log('error submit!!', errors)
      isSubmit.value = false
      uni.showToast({
        title: errors[0].message,
        icon: 'none'
      })
    }
  })
}
const getLocation = () => {
  uni.getLocation({
    type: 'gcj02',
    success: function (res) {
      console.log('当前位置的经度：' + res.longitude)
      console.log('当前位置的纬度：' + res.latitude)
      pageData.formData.lon = res.longitude
      pageData.formData.lat = res.latitude
    },
    fail: function (err) {
      console.log('errrrrr', err)
    }
  })
}

const changeStore = (store) => {
  console.log('iiiiiiii', store)
  pageData.formData.type = store.type + ''
  pageData.formData.address = store.address
  pageData.formData.fzr = store.fzr
  pageData.formData.phone = store.phone
  pageData.formData.csnumber = store.csnumber || 1
  pageData.formData.storeid = store.id
  pageData.formData.yyzt = store.status
  pageData.formData.lon = store.lon
  pageData.formData.lat = store.lat
  if(store.checktypeId) {
    let checkTypeData = []
    remoteParams.checkType.api(remoteParams.checkType.params).then(res => {
      checkTypeData = res[remoteParams.checkType.resField || 'data'].map(item => {
        return {
          text: item[remoteParams.checkType.field.text],
          value: item[remoteParams.checkType.field.value]
        }
      })
      pageData.formData.checktypeid = store.checktypeId
      const index = checkTypeData.findIndex(item => item.value === store.checktypeId)
      pageData.formData.typename = checkTypeData[index].text
    })
  }
  console.log('lonlat', pageData.formData.lon, pageData.formData.lat)
  if (!pageData.formData.lon || !pageData.formData.lat) {
    getLocation()
  }
  for(let i = 0; i < store.photoList.length; i++) {
    const imgItem = store.photoList[i]
    if (!imgItem.imgUrl) continue
    const tmpArr = imgItem.imgUrl.split('/')
    imgItem.name = tmpArr[tmpArr.length - 1]
    const tmpArr1 = imgItem.name.split('.')
    imgItem.extname = tmpArr1[tmpArr1.length - 1]
    imgItem.url = host + imgItem.imgUrl
    console.log('imgItem', imgItem)
    if (store.photoList[i].type === 1) {
      pageData.formData.signboard = [imgItem]
    }
    if (store.photoList[i].type === 2) {
      pageData.formData.license = [imgItem]
    }
  }
  // nextTick(() => {
  //   pageData.formData.signboard = signboard
  //   pageData.formData.license = license
  //   console.log('form', pageData.formData)
  // })
}

const changeDtlStatus = (v, item) => {
  item.status = v
}

const addCheckItem = () => {
  pageData.formData.recorddtls = [
      ...pageData.formData.recorddtls,
      ...[
        {
          checkinfoid: '',
          isOk: 1,
          // status: 1,
          checkPhotos: [],
          rectifyPhotos: []
        }
      ]
  ]
}
const minusCheckItem = (index) => {
  pageData.formData.recorddtls.splice(index, 1)
}
const confirmSign = (data, type) => {
  console.log('data', data)
  if (data === '') {
    return false
  }
  uni.uploadFile({
    url: uploadUrl, //上传图片的后端接口
    filePath: data,
    name: 'file',
    success: res => {
      pageData.formData[type] = JSON.parse(res.data).fileName
    }
  })
  // pageData.formData[type] = data
}

const clearSign = (type) => {
  pageData.formData[type] = ''
}
const detailId = ref('')
const isContinue = ref(false)
const loading = ref(false)
const show3 = ref(false)
const getStoreById = (id) => {
  remoteParams.store.api({id}).then(res => {
    console.log('resssssssss', res)
  })
}
onLoad(async (options) => {
  if(userInfo.permissions.includes('system:store:show3')){
    show3.value = true
  }
  
  if(options.id) {
    detailId.value = options.id
    const res = await getCheckType({})
    await getDetail(detailId.value, options.isShare)
    return
  }
  if(options.isContinue) {
    isContinue.value = true
    uni.getStorage({
      key: 'createStoreCatch',
      success: (res) => {
        console.log('createStoreCatch', res.data)
        pageData.formData = res.data
      }
    })
  }
  pageData.formData.parentName = userInfo.dept.deptName
  pageData.formData.parentId = userInfo.dept.deptId
  pageData.formData.creater = userInfo.userId
  pageData.formData.okSign1 = userInfo.signUrl
  pageData.formData.todoSign1 = userInfo.signUrl
  pageData.formData.nookSign1 = userInfo.signUrl
  if(options.name && options.xqid && options.xqname) {
    pageData.formData.xqid = options.xqid
    pageData.formData.xqname = options.xqname
    pageData.formData.csname = options.name
  }
})

let docStatus = 0

const getDetail = async(id, isShare) => {
  loading.value = true
  const api = isShare ? getrecordbyidhare : getrecordbyid
  await api({id}).then(res => {
    console.log('pageData.formData.status', pageData.formData.status)
    if ([0, 3].includes(res.data.status)) {
      res.data.okSign2 = res.data.todoSign2
      res.data.okSign3 = res.data.todoSign3
      res.data.nookSign2 = res.data.todoSign2
      res.data.nookSign3 = res.data.todoSign3
    }
    pageData.formData = res.data
    console.log('pageData.formData', pageData.formData)
    if (!pageData.formData.okSign1) {
      pageData.formData.okSign1 = userInfo.signUrl
    }
    if (!pageData.formData.todoSign1) {
      pageData.formData.todoSign1 = userInfo.signUrl
    }
    if (!pageData.formData.nookSign1) {
      pageData.formData.nookSign1 = userInfo.signUrl
    }
    docStatus = pageData.formData.status

    console.log('res.data', res.data)
    console.log('formData', pageData.formData)
    for(let i = 0; i < pageData.formData.imgList?.length; i++) {
      const imgItem = pageData.formData.imgList[i]
      if (!imgItem.imgUrl) continue
      const tmpArr = imgItem.imgUrl.split('/')
      imgItem.name = tmpArr[tmpArr.length - 1]
      const tmpArr1 = imgItem.name.split('.')
      imgItem.extname = tmpArr1[tmpArr1.length - 1]
      imgItem.url = host + imgItem.imgUrl
      if (pageData.formData.imgList[i].type === 1) {
        pageData.formData.signboard = [imgItem]
      }
      if (pageData.formData.imgList[i].type === 2) {
        pageData.formData.license = [imgItem]
      }
    }
    for (let i = 0; i < pageData.formData.recorddtls.length; i++) {
      /* if ([0, 2, 3].includes(pageData.formData.recorddtls[i].status)) {
        pageData.formData.recorddtls[i].isOk1 = 0
      } else {
        pageData.formData.recorddtls[i].isOk1 = 1
      } */
      if(pageData.formData.recorddtls[i].isOk == 0 && !pageData.formData.recorddtls[i].status){
        pageData.formData.recorddtls[i].status = 1
      }
      pageData.formData.recorddtls[i].checkPhotos = []
      pageData.formData.recorddtls[i].rectifyPhotos = []
      for (let j = 0; j < pageData.formData.recorddtls[i].photoList.length; j++) {
        const photoItem = pageData.formData.recorddtls[i].photoList[j]
        if (!photoItem.imgUrl) continue
        const tmpArr = photoItem.imgUrl.split('/')
        photoItem.name = tmpArr[tmpArr.length - 1]
        const tmpArr1 = photoItem.name.split('.')
        photoItem.extname = tmpArr1[tmpArr1.length - 1]
        photoItem.url = host + photoItem.imgUrl
        if (photoItem.type === 3) {
          pageData.formData.recorddtls[i].checkPhotos.push(photoItem)
        }
        if (photoItem.type === 4) {
          pageData.formData.recorddtls[i].rectifyPhotos.push(photoItem)
        }
      }
    }
    const params = {
      typeid: pageData.formData.checktypeid
    }
    getCheckInfoList(params).then(res => {
      nextTick(() => {
        pageData.checkInfoList = res.data.map(item => {
          return {
            value: item.id,
            text: item.content
          }
        })
        loading.value = false
      })
    })
    console.log('formData1', pageData.formData)
  })
}

const fullscreenSign = ref(null)
const isFullScreen = ref(false)
const currentSign = ref('')
const closeFullScreen = () => {
  isFullScreen.value = false
}
const setFullScreen = (v, field) => {
  isFullScreen.value = true
  currentSign.value = field
}
const signWidth = ref(null)
const signHeight = ref(null)
const confirmSignFs = (canvas, data, type) => {
  // console.log('data', canvas, data)
  // console.log('canvas', canvas.canvasId)
  uni.getImageInfo({
    src: data,
    success: function(res) {
      signWidth.value = res.width
      signHeight.value = res.height
      console.log('wh', signWidth.value, signHeight.value)
      const ctx = uni.createCanvasContext('fullscreenCanvas')
      console.log('ctx', ctx)
      ctx.translate(0, signWidth.value)
      ctx.rotate((270 * Math.PI) / 180)
      ctx.drawImage(data, 0, 0, signWidth.value, signHeight.value)
      // ctx.drawImage(data, 0, 0, width, height)
      ctx.draw()
      setTimeout(() => {
        uni.canvasToTempFilePath({
          canvasId: 'fullscreenCanvas',
          success: function(res) {
            // 在H5平台下，tempFilePath 为 base64
            // console.log('resssssssss', res.tempFilePath)
            uni.uploadFile({
              url: uploadUrl, //上传图片的后端接口
              filePath: res.tempFilePath,
              name: 'file',
              success: res => {
                // console.log('rrrrrrrrr', res)
                pageData.formData[type] = JSON.parse(res.data).fileName
                isFullScreen.value = false
              }
            })
            pageData.formData[type] = data
          },
          fail: function (err) {
            console.log('errrrrrrr', err)
          }
        })
      }, 200)
    },
    fail: function(res) {
      console.log('errr', res)
    }
  })
}

Object.assign(dict, uni.getStorageSync('dict'))

const hiddenOk = ref(1)


const uploadDel = (e) => {
  console.log('eeeeee', e)
  if (!e.id) return
  const params = {
    id: e.id
  }
  delphoto(params)
}

const save = () => {
  uni.setStorage({
    key: 'createStoreCatch',
    data: pageData.formData,
    success: () => {
      uni.showToast({
        title: '暂存成功！',
        icon: 'success'
      })
    }
  })
}
const changeIsOk1 = (v, item) => {
  console.log('item', v, item)
  item.status = v ? 1 : 0
}

const showEg = ref(false)
const egInfo = ref({})
const handlePopupEg = (item) => {
  console.log('item', item)
  egInfo.value = item
  showEg.value = true
}
</script>

<template>
  <nut-loading-page :loading="loading" />
  <nut-form :model-value="pageData.formData" ref="formData" :rules="formRule">
    <nut-collapse v-model="pageData.activeCollapse" :accordion="true">
      <nut-collapse-item title="基础信息" :name="1">
        <nut-form-item label="主管部门" prop="parentName" label-width="70">
          <nut-input v-model="pageData.formData.parentName" readonly />
        </nut-form-item>
        <nut-form-item label="所属管辖" prop="xqid" label-width="70">
          <select-popup v-model="pageData.formData.xqid" :echo="pageData.formData.xqname" is-remote :remote-params="remoteParams.xq"></select-popup>
        </nut-form-item>
        <nut-form-item label="场所名称" prop="csname" label-width="70">
          <select-store v-model="pageData.formData.csname" :placeholder="placeholder.csnamePh" :disabled="!pageData.formData.xqid" :remote-params="remoteParams.store" @change="changeStore"></select-store>
        </nut-form-item>
        <nut-form-item label="场所类别" prop="type" label-width="70">
          <select-popup v-model="pageData.formData.type" :echo="pageData.formData.dictLabel" :columns="dict.store_type"></select-popup>
        </nut-form-item>
        <nut-form-item label="总分值" prop="scoreTotal" v-if="pageData.formData.id">
          <nut-input v-model="pageData.formData.scoreTotal" readonly />
        </nut-form-item>
        <nut-form-item v-if="pageData.formData.signboard" label="门头" prop="signboard" label-width="70">
          <uploader v-model="pageData.formData.signboard" :url="uploadUrl" return-type="object" type="1" :limit="1"></uploader>
        </nut-form-item>
        <nut-form-item v-if="pageData.formData.license" label="营业执照" prop="license" label-width="70">
          <uploader v-model="pageData.formData.license" :url="uploadUrl" return-type="object" type="2" :limit="1"></uploader>
        </nut-form-item>
        <nut-form-item v-if="!pageData.formData.signboard" label="门头" prop="signboard" label-width="70">
          <uploader v-model="pageData.formData.signboard" :url="uploadUrl" return-type="object" type="1" :limit="1"></uploader>
        </nut-form-item>
        <nut-form-item v-if="!pageData.formData.license" label="营业执照" prop="license" label-width="70">
          <uploader v-model="pageData.formData.license" :url="uploadUrl" return-type="object" type="2" :limit="1"></uploader>
        </nut-form-item>
        <nut-form-item label="地址" prop="address" label-width="70">
          <nut-input v-model="pageData.formData.address" placeholder="请输入文本" />
        </nut-form-item>
        <nut-form-item label="负责人" prop="fzr" label-width="70">
          <nut-input v-model="pageData.formData.fzr" placeholder="请输入文本" />
        </nut-form-item>
        <nut-form-item label="联系方式" prop="phone" label-width="70">
          <nut-input v-model="pageData.formData.phone" placeholder="请输入文本" />
        </nut-form-item>
        <nut-form-item label="场所人数" prop="csnumber" label-width="70">
          <nut-input-number v-model="pageData.formData.csnumber" input-width="100" min="1" />
        </nut-form-item>
        
        <view v-if="show3">
          <nut-form-item label="场所层数" prop="cengshu" label-width="70">
            <nut-input-number v-model="pageData.formData.cengshu" input-width="100" min="0" />
          </nut-form-item>
          <nut-form-item label="场所面积" prop="mianji" label-width="70">
            <nut-input-number v-model="pageData.formData.mianji" step="0.01" decimal-places="2" input-width="100" min="0" />
          </nut-form-item>
          <nut-form-item label="独立烟感数量" prop="yanganshu" label-width="90">
            <nut-input-number v-model="pageData.formData.yanganshu" input-width="100" min="0" />
          </nut-form-item>
        </view>
        <nut-form-item label="营业状态" prop="status" label-width="70">
          <nut-radio-group v-model="pageData.formData.yyzt" direction="horizontal">
            <nut-radio v-for="(item, index) in dict.store_status" :key="item.value" :label="item.value - 0">{{ item.text }}</nut-radio>
          </nut-radio-group>
        </nut-form-item>
<!--        <nut-form-item label="检查日期" prop="date" label-width="70">-->
<!--          <date-popup v-model="pageData.formData.date"></date-popup>-->
<!--        </nut-form-item>-->
      </nut-collapse-item>
      <nut-collapse-item title="检查内容" :name="2">
        <nut-form-item v-if="pageData.formData.id" label="是否隐藏合格项" prop="hiddenOk" label-width="140">
          <nut-switch v-model="hiddenOk" :active-value="1" :inactive-value="0" active-color="green"/>
        </nut-form-item>
        <nut-form-item label="检查类型" prop="checktypeid" label-width="70" :rules="[
                {
                  required: true,
                  message: '请选择检查类型'
                }
            ]">
          <select-popup v-model="pageData.formData.checktypeid" :echo="pageData.formData.typename" is-remote :remote-params="remoteParams.checkType"></select-popup>
        </nut-form-item>
        <nut-divider dashed />
        <nut-row v-for="(item, index) in pageData.formData.recorddtls" :key="index">
          <nut-col v-if="!pageData.formData.id || item.isOk !== 1 || !hiddenOk" :span="24" style="border-top: 1px solid #aaa;">
            <nut-form-item v-if="item.checkinfoid && pageData.checkInfoList.length" :label="'检查内容'+Number(index+1)" :prop="'recorddtls.' + index + '.checkinfoid'" label-width="90" :rules="[
                {
                  required: true,
                  message: '请选择检查内容'
                }
            ]">
              <select-popup v-model="item.checkinfoid" :columns="pageData.checkInfoList" :placeholder="item.checkinfo" :echo="item.checkinfo" :disabled="!pageData.formData.checktypeid"></select-popup>
            </nut-form-item>
            <nut-form-item :prop="'recorddtls.' + index + '.checkPhotos'" label-width="70">
              <template #label>
                <view>检查照片</view>
                <view v-if="item.egPic" class="eg" @click="handlePopupEg(item)"><nut-icon name="tips" custom-color="#fa2c19"></nut-icon></view>
              </template>
              <uploader v-model="item.checkPhotos" :url="uploadUrl" type="3" @uploadDel="uploadDel"></uploader>
            </nut-form-item>
            <nut-form-item label="是否合格" prop="isOk">
              <template v-if="pageData.formData.id">
                <nut-tag v-if="item.isOk == 1" type="success">合格</nut-tag>
                <nut-tag v-else type="danger">不合格</nut-tag>
              </template>
              <nut-switch v-model="item.isOk" v-else :active-value="1" :inactive-value="0" active-color="green"/>
            </nut-form-item>
            <nut-form-item label="分值" prop="score" v-if="item.isOk == 0 && !pageData.formData.id">
              <view style="color: #000;">{{ item.score }}</view>
            </nut-form-item>
            <nut-form-item label="备注" prop="remark">
              <nut-input v-model="item.remark" placeholder="请输入备注" max-length="50" />
            </nut-form-item>
            <nut-form-item v-if="item.isOk === 0" label="整改建议" :prop="'recorddtls.' + index + '.content'" label-width="70" :rules="[
                {
                  required: true,
                  message: '请输入整改建议'
                }
            ]">
              <view style="color: #000;">{{ item.content }}</view>
              <!-- <nut-input v-model="item.content" placeholder="请输入文本" /> -->
            </nut-form-item>
            <nut-form-item v-if="item.isOk === 0 && item.recordId" label="整改照片" :prop="'recorddtls.' + index + '.rectifyPhotos'" label-width="70">
              <uploader v-model="item.rectifyPhotos" :url="uploadUrl" type="4" @uploadDel="uploadDel"></uploader>
            </nut-form-item>
            <nut-form-item v-if="item.isOk === 0 && item.recordId" label="是否合格" prop="status" label-width="70">
              <nut-switch v-model="item.status" :active-value="1" :inactive-value="0" @change="(v) => changeIsOk1(v, item)" active-color="green"/>
            </nut-form-item>
          </nut-col>
          
          <nut-col v-if="!pageData.formData.id || item.isOk === 0 || !hiddenOk" :span="24">
            <!-- <view style="height: 1px;background: #eee;"></view> -->
            <nut-divider dashed />
          </nut-col>
        </nut-row>
      </nut-collapse-item>
      <nut-collapse-item v-if="getFormStatus === 1 && !userInfo.roleIds.includes(106)" title="合格签字" :name="3">
        <nut-form-item label="检查人员签字(合格)" prop="okSign1" label-width="70">
          <view v-if="pageData.formData.okSign1">
            <image :src="host + pageData.formData.okSign1" style="width: 260px;height: 150px;" />
            <nut-button size="mini" type="primary" @click="clearSign('okSign1')">重签</nut-button>
          </view>
          <signature v-else :field="'okSign1'" @confirm="confirmSign" @clear="clearSign" @set-full-screen="(v) => setFullScreen(v, 'okSign1')"></signature>
        </nut-form-item>
        <nut-form-item label="场所人员签字(合格)" prop="okSign2" label-width="70">
          <view v-if="pageData.formData.okSign2">
            <image :src="host + pageData.formData.okSign2" style="width: 260px;height: 150px;" />
            <nut-button size="mini" type="primary" @click="clearSign('okSign2')">重签</nut-button>
          </view>
          <signature v-else :field="'okSign2'" @confirm="confirmSign" @clear="clearSign" @set-full-screen="(v) => setFullScreen(v, 'okSign2')"></signature>
        </nut-form-item>
        <nut-form-item label="主管部门签字(合格)" prop="okSign3" label-width="70">
          <view v-if="pageData.formData.okSign3">
            <image :src="host + pageData.formData.okSign3" style="width: 260px;height: 150px;" />
            <nut-button size="mini" type="primary" @click="clearSign('okSign3')">重签</nut-button>
          </view>
          <signature v-else :field="'okSign3'" @confirm="confirmSign" @clear="clearSign" @set-full-screen="(v) => setFullScreen(v, 'okSign3')"></signature>
        </nut-form-item>
      </nut-collapse-item>
      <nut-collapse-item v-if="getFormStatus === 0 && !userInfo.roleIds.includes(106)" title="整改签字" :name="3">
        <nut-form-item label="检查人员签字(整改)" prop="todoSign1" label-width="70">
          <view v-if="pageData.formData.todoSign1">
            <image :src="host + pageData.formData.todoSign1" style="width: 260px;height: 150px;" />
            <nut-button size="mini" type="primary" @click="clearSign('todoSign1')">重签</nut-button>
          </view>
          <signature v-else :field="'todoSign1'" @confirm="confirmSign" @clear="clearSign" @set-full-screen="(v) => setFullScreen(v, 'todoSign1')"></signature>
        </nut-form-item>
        <nut-form-item label="场所人员签字(整改)" prop="todoSign2" label-width="70">
          <view v-if="pageData.formData.todoSign2">
            <image :src="host + pageData.formData.todoSign2" style="width: 260px;height: 150px;" />
            <nut-button size="mini" type="primary" @click="clearSign('todoSign2')">重签</nut-button>
          </view>
          <signature v-else :field="'todoSign2'" @confirm="confirmSign" @clear="clearSign" @set-full-screen="(v) => setFullScreen(v, 'todoSign2')"></signature>
        </nut-form-item>
        <nut-form-item label="主管部门签字(整改)" prop="todoSign3" label-width="70">
          <view v-if="pageData.formData.todoSign3">
            <image :src="host + pageData.formData.todoSign3" style="width: 260px;height: 150px;" />
            <nut-button size="mini" type="primary" @click="clearSign('todoSign3')">重签</nut-button>
          </view>
          <signature v-else :field="'todoSign3'" @confirm="confirmSign" @clear="clearSign" @set-full-screen="(v) => setFullScreen(v, 'todoSign3')"></signature>
        </nut-form-item>
      </nut-collapse-item>
      <nut-collapse-item v-if="getFormStatus === 2 && !userInfo.roleIds.includes(106)" title="不合格签字" :name="3">
        <nut-form-item label="检查人员签字(不合格)" prop="nookSign1" label-width="70">
          <view v-if="pageData.formData.nookSign1">
            <image :src="host + pageData.formData.nookSign1" style="width: 260px;height: 150px;" />
            <nut-button size="mini" type="primary" @click="clearSign('nookSign1')">重签</nut-button>
          </view>
          <signature v-else :field="'nookSign1'" @confirm="confirmSign" @clear="clearSign" @set-full-screen="(v) => setFullScreen(v, 'nookSign1')"></signature>
        </nut-form-item>
        <nut-form-item label="场所人员签字(不合格)" prop="nookSign2" label-width="70">
          <view v-if="pageData.formData.nookSign2">
            <image :src="host + pageData.formData.nookSign2" style="width: 260px;height: 150px;" />
            <nut-button size="mini" type="primary" @click="clearSign('nookSign2')">重签</nut-button>
          </view>
          <signature v-else :field="'nookSign2'" @confirm="confirmSign" @clear="clearSign" @set-full-screen="(v) => setFullScreen(v, 'nookSign2')"></signature>
        </nut-form-item>
        <nut-form-item label="主管部门签字(不合格)" prop="nookSign3" label-width="70">
          <view v-if="pageData.formData.nookSign3">
            <image :src="host + pageData.formData.nookSign3" style="width: 260px;height: 150px;" />
            <nut-button size="mini" type="primary" @click="clearSign('nookSign3')">重签</nut-button>
          </view>
          <signature v-else :field="'nookSign3'" @confirm="confirmSign" @clear="clearSign" @set-full-screen="(v) => setFullScreen(v, 'nookSign3')"></signature>
        </nut-form-item>
      </nut-collapse-item>
    </nut-collapse>
  </nut-form>
  <nut-cell v-if="!userInfo.roleIds.includes(106)">
    <nut-row :gutter="20">
      <nut-col :span="12">
        <nut-button :loading="loadingBtn" type="success" block @click="submit(false)">提交</nut-button>
      </nut-col>
      <nut-col :span="12">
        <nut-button :loading="loadingBtn" type="default" block @click="save">暂存</nut-button>
      </nut-col>
    </nut-row>
  </nut-cell>
  <view v-if="isFullScreen" class="fullscreen-sign">
    <view class="sign">
      <nut-signature
          ref="fullscreenSign"
          custom-class="fullscreenSign"
          @confirm="(canvas, data) => confirmSignFs(canvas, data, currentSign)"
          @clear="clearSign(currentSign)"
      />
      <canvas v-if="signWidth && signHeight" canvas-id="fullscreenCanvas" :style="`width:${signHeight}px; height:${signWidth}px;position: absolute;left: -9999px;`"></canvas>
    </view>
    <view class="btn">
      <nut-button type="primary" @click="closeFullScreen">关闭全屏</nut-button>
    </view>
  </view>
  <nut-popup position="bottom" v-model:visible="showEg">
    <view class="head-popup">图片示例</view>
    <view class="body-popup">
      <nut-form>
        <nut-form-item label="检查内容">
          {{ egInfo.content }}
        </nut-form-item>
        <nut-form-item label="示例图片">
          <image style="width: 200px; height: 200px;" :src="host + egInfo.egPic"></image>
        </nut-form-item>
      </nut-form>
    </view>
  </nut-popup>
  <nut-safe-area position="bottom" />
  <nut-dialog
    teleport="#app"
    title="提示"
    :content="scoreTotalText"
    :onOk="clickOk"
    v-model:visible="visibleScore">
  </nut-dialog>
</template>

<style scoped lang="scss">
.row{width: 50%;}
.eg{padding: 10px 0 0;text-align: center}
.head-popup{padding: 20px 0 10px;text-align: center;font-size: 20px}
</style>
